package com.zzw.thread.concurrent;

import java.util.concurrent.CountDownLatch;

import org.junit.Test;

public class CountDownLatchTest {

	private static CountDownLatch countDownLatch = new CountDownLatch(2);
	
	@Test
	public void run() throws InterruptedException{
		Thread parse1 = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println(Thread.currentThread().getName() + "---parsing txt file1 start");
				countDownLatch.countDown();
				System.out.println(Thread.currentThread().getName() + "---parsing txt file1 success");
			}
		});
		
		Thread parse2 = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println(Thread.currentThread().getName() + "---parsing txt file2 start");
				countDownLatch.countDown();
				System.out.println(Thread.currentThread().getName() + "---parsing txt file2 success");
			}
		});
		
		parse1.start();
		parse2.start();
		countDownLatch.await();
		System.out.println("parsing txt file success");
	}
}